<?php
/**
 * XmlRpc编码关联数组数据
 *
 * @version $Id: XmlRpcStructEncoder.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.rai.format.xmlrpc.encoder
 * @since 0.0.3
 */
class XmlRpcStructEncoder extends AbstractXmlRpcEncoder {
	public function asDOM() {
		$document = new DOMDocument("1.0", $this->getCharset());
		$child = $document->appendChild($document->createElement("struct"));
		foreach ($this->getVar() as $name=>$value) {
			if (!preg_match("/^[a-z_][\w\.\-]*$/", $name)) {
				continue;
			}
			$member = $child->appendChild($document->createElement("member"));
			$member->appendChild($document->createElement("name", $name));
			$valueElement = $member->appendChild($document->createElement("value"));
			$valueElement->appendChild($document->importNode(XmlRpcHelper::getEncoder($value, $this->getCharset())->asDOM()->firstChild, true));
		}
		return $document;
	}	
}


?>